#include "sys.h"
#include "usart.h"
#include "delay.h" 
#include "timer.h"
#include "ADC.h"
#include "usart3.h"
#include "oled.h"
#include "math.h"
#include "dht11.h"
#include "bmp280.h"
#include "gizwits_product.h" 
#include "gizwits_protocol.h" 
#include "switch.h"
#include "configs.h"
#include "app.h"

#define FLASH_SAVE_ADDR 0x08010000
void Gizwits_Init(void)
{	
	TIM3_Int_Init(71,999);
  usart3_init(9600);
	gizwitsInit();
}

int main(void)
{	
	STRAppAttrType attrs;
	RCC->APB2ENR |= (RCC_APB2ENR_IOPAEN | RCC_APB2ENR_IOPBEN 
			| RCC_APB2ENR_IOPCEN | RCC_APB2ENR_IOPDEN 
			| RCC_APB2ENR_IOPEEN | RCC_APB2ENR_IOPEEN
			 | RCC_APB2ENR_AFIOEN);//PORTA clock enable
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB|RCC_APB2Periph_AFIO, ENABLE);	 
	GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable,ENABLE); //PB3 PA13 
  RCC->APB2ENR |= (RCC_APB2ENR_USART1EN | RCC_APB2ENR_SPI1EN);
	RCC->APB1ENR |=  (RCC_APB1ENR_USART3EN| RCC_APB1ENR_USART2EN);
	RCC->APB1ENR |= RCC_APB1ENR_PWREN;
	delay_init();
	uart_init(115200);	 		    
	NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
	Adc1_Channe_Init();			
	bmp280Init();
	OLED_Init();				
	OLED_Clear();				
	Gizwits_Init();	
	fnSW_Init();
	fnConfigs_Init();
	fnApp_Init();	
	while(1)
	{
		fnTM_RealTime();
		fnSW_RealTime();
		fnApp_RealTime();
		fnSW_Clear();
		fnTM_Clear();
		gizwitsHandle((dataPoint_t *)&currentDataPoint);
	}
}
 
